<template>
    <el-container>
        <el-container class="is-vertical">
            <div class="panel-search-box">
                <div class="panel-search">
                    <el-date-picker v-model="search.timeRange" type="datetimerange" value-format="YYYY-MM-DD HH:mm:ss" format="YYYY-MM-DD HH:mm:ss"
							range-separator="至" start-placeholder="开始时间" end-placeholder="结束时间" class="sDateSelect" style="margin-left:10px;"
						>
                    </el-date-picker>
                    <el-button type="primary" icon="el-icon-search" @click="upsearch"></el-button>
                </div>
            </div>
            <el-main class="nopadding" style="min-height:500px;">
                <scDialogTable ref="table" :apiObj="$API.learn.list" :params="search" remoteSort @dataChange="dataChange" :height="500">
                    <el-table-column label="序号" prop="index" width="70" align="left"></el-table-column>
                    <el-table-column label="姓名" prop="teacher" align="center" width="120">
                        <template #default="scope">
                            {{scope.row.teacher ? scope.row.teacher.name : ''}}
                        </template>
                    </el-table-column>
                    <el-table-column label="课程名称" prop="course" width="120" align="center">
                        <template #default="scope">
                            {{scope.row.course ? scope.row.course.name : ''}}
                        </template>
                    </el-table-column>
                    <el-table-column label="开始时间" prop="startTime" width="150" align="center"></el-table-column>
                    <el-table-column label="结束时间" prop="endTime" width="150" align="center"></el-table-column>
                    <el-table-column label="总数" prop="totalWords" width="150" align="center"></el-table-column>
                    <el-table-column label="正确数" prop="rightNumber" width="150" align="center"></el-table-column>
                    <el-table-column label="错误数" prop="wrongNumber" width="150" align="center"></el-table-column>
                </scDialogTable>
            </el-main>
        </el-container>
    </el-container>


    <detail-dialog v-if="dialog.detail" ref="detailDialog" @closed="dialog.detail=false"></detail-dialog>

</template>

<script>
import detailDialog from '../detail.vue'
export default {
    components: {
        detailDialog
    },
    props: {
		learnType: { type: Number, default: () => 0 },
        teacherId: { type: Number, default: () => 0 },
	},
    data() {
        return {
            dialog: {
                detail: false,
            },
            search: {
                name: null,
                learnType: null,
            }
        }
    },
    created() {
        this.search.learnType = this.learnType
        this.search.teacherId = this.teacherId
    },
    mounted() {
        
    },
    methods: {
        dataChange(res, tableData) {
			let total = res.data.total
            let perPage = res.data.perPage
            let page = (this.$refs.table && this.$refs.table.currentPage) || 1
            tableData.forEach((item, index) => {
				item.index = page * perPage + index - perPage + 1
            })
        },
        //查看
        table_show(row) {
            this.dialog.detail = true
			this.$nextTick(() => {
				this.$refs.detailDialog.open(row.id)
			})
        },
        // 搜索
        upsearch() {
            this.$refs.table.upData(this.search)
        },
        //本地更新数据
        handleSuccess() {
            this.$refs.table.refresh()
        }
    }
}
</script>

<style>
.position {
    display: flex;
    align-items: center;
}
.position-item {
    margin-right: 5px;
}
.position-item:last-child {
    margin-right: 0;
}
</style>
